package com.chinasolf.service.impl;

import com.chinasoft.vo.msm.MsmVo;
import com.chinasolf.service.MsmService;
import com.chinasolf.utils.HttpUtils;
import org.apache.http.HttpResponse;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class MsmServiceImpl implements MsmService {
        //发送验证码
        @Override
        public boolean sendDx (String phone, String code){
            String host = "http://dingxin.market.alicloudapi.com";
            String path = "/dx/sendSms";
            String method = "POST";
            String appcode = "1db7981205234de5b211edbc6a26c085";
            Map<String, String> headers = new HashMap<String, String>();
            //Authorization:APPCODE 83359fd73fe94948385f570e3c139105
            headers.put("Authorization", "APPCODE " + appcode);
            Map<String, String> querys = new HashMap<String, String>();
            querys.put("mobile", phone);
            querys.put("param", "code:" + code);
            querys.put("tpl_id", "TP1711063");
            Map<String, String> bodys = new HashMap<String, String>();
            try {
                HttpResponse response = HttpUtils.doPost(host, path, method, headers,
                        querys, bodys);
                System.out.println(response.toString());
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }

    @Override
    public void send(MsmVo msmVo) {
        String phone = msmVo.getPhone();
        System.out.println(phone+"手机号短信已经发送了");
    }
}
